import { isPlainObject, isArray } from 'dtc'

function _getAllChildComp(instance) {
  let allComp = [],
    child
  if (isPlainObject(instance)) {
    child = instance.$children
  } else if (isArray(instance)) {
    child = instance
  }
  for (let i = 0; i < child.length; i++) {
    allComp.push(child[i])
    if (child[i].$children.length > 0) {
      allComp = allComp.concat(_getAllChildComp(child[i].$children))
    }
  }
  return allComp
}
function _getCompByTagName(tag) {
  let components = [],
    queryComps
  queryComps = _getAllChildComp(app.root)
  components = queryComps.filter((vm) => {
    return vm.$options._componentTag === tag
  })
  return components
}
export default _getCompByTagName
